package cn.edu.zut.cs;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class MyConnection {

    private MyConnection(){}

    public static Connection getConnection() throws Exception {

        Connection conn = null;

        Properties prop = getProp();
        String driver = prop.getProperty("driverClassName");
        String user = prop.getProperty("mysql.userName");
        String url = prop.getProperty("mysql.url");
        String pwd = prop.getProperty("mysql.password");

        Class.forName(driver);

        conn = DriverManager.getConnection(url , user , pwd);

        return conn;
    }
    public static Properties getProp() throws Exception{
        Properties prop = new Properties();
        FileInputStream fin = new FileInputStream( MyConnection
                .class
                .getClassLoader()
                .getResource("mysql.properties")
                .getPath());
        prop.load(fin);
        return prop;
    }
}
